export class HashMap
{
    private mLength:number;
	private mData:any;
    private mArray: any[];
    
    constructor()
    {
        this.mLength = 0
        this.mData  = {}
        this.mArray = [];
    }

    IsEmpty() {
        return this.mLength == 0;
    }

    ContainsKey(key) {
        let ret = false;
        if (this.mData[key]) {
            ret = true;
        }
        return ret;
    }
	
    Set(key, value) {
        if (value == null) {
            return
        }
        
        if (this.ContainsKey(key) == false) {
            this.mLength = this.mLength + 1;
            this.mArray.push(value);
        } else {
            const oldValue = this.mData[key];
            const index = this.mArray.indexOf(oldValue);
            if (index >= 0){
                this.mArray[index] = value;
            }
        }
        this.mData[key] = value;
    }

    Get(key) {
        if (this.ContainsKey(key) == false) {
            return null;
        }
        return this.mData[key];
    }

    Remove(key) {
        if (this.ContainsKey(key) == false ){
            return;
        }
        const oldValue = this.mData[key];
        const index = this.mArray.indexOf(oldValue);
        if (index >= 0){
            this.mArray.splice(index);
        }
        
        this.mData[key] = null;
        this.mLength = this.mLength - 1;
    }

    Size() {
        return this.mLength;
    }

    Array() {
        return this.mArray;
    }
    
    Index(index) {
        return this.mArray[index];
    }

    Clear() {
        this.mData = {};
        this.mArray = [];
        this.mLength = 0;
    }
}